package org.jgs1904.practice;

/**
 * @author: 默苍璃
 * @date: 2022-09-16 16:27
 * <p>
 * 如果传入的参数为负，则抛出IllegalArgumentException。
 */
public class Practice02 {
    public static void main(String[] args) {
        try {
            System.out.println(tax(2000, 0.1));
            System.out.println(tax(-200, 0.1));
            System.out.println(tax(2000, -0.1));
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    static double tax(int salary, double rate) {
        // TODO: 如果传入的参数为负，则抛出IllegalArgumentException
        if (salary < 0 || rate < 0) {
            throw new IllegalArgumentException();
        }
        return salary * rate;
    }
}
